<?php

    //Sub Table Class define
    include_once("ClassSub.php");

class RoomsClass
{
	var $BedroomDetail;
	var $DiningRoom;
	var $LivingRoom;
	var $FamilyRoom;
    var $Basement;
    var $TotalRooms;
	
	var $ID;
	
	function AddItemFromXML($XmlArray)
	{
		$Array = $XmlArray->children();
			
	 	$this->BedroomDetail = new BedroomDetailClass;
		$this->BedroomDetail->AddItemFromXML($Array[0]);
	 	$this->DiningRoom = new AreaRoomFormatClass;
		$this->DiningRoom->AddItemFromXML($Array[1]);
	 	$this->LivingRoom = new AreaRoomFormatClass;
		$this->LivingRoom->AddItemFromXML($Array[2]);
	 	$this->FamilyRoom = new AreaRoomFormatClass;
		$this->FamilyRoom->AddItemFromXML($Array[3]);
	 	$this->Basement = new AreaRoomFormatClass;
		$this->Basement->AddItemFromXML($Array[4]);
		$this->TotalRooms = $Array[5];
	}
	
	function InsertSQL()
	{
		$this->DiningRoom->InsertSQL();		
		$this->LivingRoom->InsertSQL();		
		$this->FamilyRoom->InsertSQL();		
		$this->Basement->InsertSQL();		

		$strSqlCommand = "INSERT INTO Rooms( DiningRoom, LivingRoom, ";
		$strSqlCommand .="FamilyRoom, Basement, TotalRooms) ";
		$strSqlCommand .= "VALUES( '".$this->DiningRoom->ID."', ";
		$strSqlCommand .= "'".$this->LivingRoom->ID."', ";
		$strSqlCommand .= "'".$this->FamilyRoom->ID."', ";
		$strSqlCommand .= "'".$this->Basement->ID."', ";
		$strSqlCommand .= "'".$this->TotalRooms."') ";
				
		if(!mysql_query($strSqlCommand))
		{
			echo $strSqlCommand."<br/>";
		}
		$this->ID = mysql_insert_id();		

		$this->BedroomDetail->InsertSQL( $this->ID );		

	}
	
	function ModifySQL( $InputID )
	{
		$this->ID = $InputID;

		$strSqlCommand = "SELECT * FROM Rooms ";
		$strSqlCommand .= " WHERE idRooms = '".$this->ID."' ";
		$result = mysql_query($strSqlCommand);
		$rowListingData = @mysql_fetch_array($result);

		$strSqlCommand =  "UPDATE Rooms SET ";
		$strSqlCommand .= "TotalRooms='"		.$this->TotalRooms		."' ";
		$strSqlCommand .= "WHERE idRooms = ".$this->ID;
		mysql_query($strSqlCommand);

		$this->BedroomDetail->InsertSQL();		
		$this->DiningRoom->InsertSQL();		
		$this->LivingRoom->InsertSQL();		
		$this->FamilyRoom->InsertSQL();		
		$this->Basement->InsertSQL();	
	}	
}

class BedroomDetailClass
{
	var $BedroomList;
	
	var $ID;
	
	function AddItemFromXML($XmlArray)
	{
		$Array = $XmlArray->children();
		
		foreach($Array as $Bedroom)	
		{
			$Temp = new AreaRoomFormatClass;
			$Temp->AddItemFromXML($Bedroom);
			$this->BedroomList[] = $Temp;
		}
	}
	
	function InsertSQL( $InputID)
	{
		foreach($this->BedroomList as $Bedroom)	
		{
			$Bedroom->InsertSQL();

			$strSqlCommand = "INSERT INTO BedroomDetail( Rooms_idRooms, AreaRoomFormat_idLotSize) ";
			$strSqlCommand .= "VALUES( '".$InputID."', ";
			$strSqlCommand .= "'".$Bedroom->ID."') ";
		}

		if(!mysql_query($strSqlCommand))
		{
			echo $strSqlCommand."<br/>";
		}
//		$this->ID = mysql_insert_id();		
	}
	
	function ModifySQL( $InputID )
	{
/*		$this->ID = $InputID;

		$strSqlCommand = "SELECT * FROM Rooms ";
		$strSqlCommand .= " WHERE idRooms = '".$this->ID."' ";
		$result = mysql_query($strSqlCommand);
		$rowListingData = @mysql_fetch_array($result);

		$strSqlCommand =  "UPDATE Rooms SET ";
		$strSqlCommand .= "TotalRooms='"		.$this->TotalRooms		."' ";
		$strSqlCommand .= "WHERE idRooms = ".$this->ID;
		mysql_query($strSqlCommand);

		$this->BedroomDetail->InsertSQL();		
		$this->DiningRoom->InsertSQL();		
		$this->LivingRoom->InsertSQL();		
		$this->FamilyRoom->InsertSQL();		
		$this->Basement->InsertSQL();	
*/
	}	
}
?>